package lock;



import Task.Task;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class JavaThreadPoolDeomo {
    public static void main(String[] args) {

        final ThreadPoolExecutor pool = new ThreadPoolExecutor(2, 3, 60,
                TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(5),
                Executors.defaultThreadFactory());
        for (int i = 0; i < 9; i++) {
            pool.execute(new Task(i));
        }
        pool.shutdown();                                                //不再接受新任务，如果还有任务仍然要全部执行完毕
        pool.shutdownNow();             //马上执行到安全点退出，不再执行线程中任务。队列中的任务不再执行，也不再接受新任务。清理完成后转换到Tidying,准备进入Terminated
    }

}
